# -*- coding: utf-8 -*-
# @Author : y
# @Date   : 2022/4/22
# @File   : 
# @E-mail : zhaochen@bbdservice.com

'''eof
name:企业失信被执行案件司法校验
code:R87_EG_EntSxbaxrCaseCheck_SC
tableName:
columnName:
groups:个人及企业司法校验
dependencies:EG_CASE_EDMP
type:常用指标
datasourceType:在线指标
description:
eof'''

import io
import pandas as pd
import json
import datetime
from collections import OrderedDict
from dateutil.relativedelta import relativedelta


def getTable2(object, caseType):
    """
    object: 'person','enterprise'
    caseType:'sxbzxr','xgbzxr'
    """
    null_type_list = ['', ' ', None, 'null', 'Null', 'NULL', '/', '-', '--']
    data = []
    if object == 'enterprise':
        try:
            data1 = EG_CASE_EDMP.get('data').get('FR003')
            if data1 in null_type_list:
                return u'缺失值'
            else:
                pass
            for i in data1:
                try:
                    sxbzxr1 = i.get(caseType)
                    if sxbzxr1 in null_type_list:
                        return u'缺失值'
                    elif sxbzxr1 == []:
                        pass
                    else:
                        data.append(sxbzxr1)
                except:
                    return u'缺失值'

            data2 = EG_CASE_EDMP.get('data').get('R003')
            if data2 in null_type_list:
                return u'缺失值'
            else:
                pass
            for j in data2:
                try:
                    sxbzxr2 = j.get(caseType)
                    if sxbzxr2 in null_type_list:
                        return u'缺失值'
                    elif sxbzxr2 == []:
                        pass
                    else:
                        data.append(sxbzxr2)
                except:
                    return u'缺失值'
        except:
            return u'缺失值'
    else:
        try:
            data1 = EG_CASE_EDMP.get('data').get('FR004')
            if data1 in null_type_list:
                return u'缺失值'
            else:
                pass
            for i in data1:
                try:
                    sxbzxr1 = i.get(caseType)
                    if sxbzxr1 in null_type_list:
                        return u'缺失值'
                    elif sxbzxr1 == []:
                        pass
                    else:
                        data.append(sxbzxr1)
                except:
                    return u'缺失值'

            data2 = EG_CASE_EDMP.get('data').get('R004')
            if data2 in null_type_list:
                return u'缺失值'
            else:
                pass
            for j in data2:
                try:
                    sxbzxr2 = j.get(caseType)
                    if sxbzxr2 in null_type_list:
                        return u'缺失值'
                    elif sxbzxr2 == []:
                        pass
                    else:
                        data.append(sxbzxr2)
                except:
                    return u'缺失值'
        except:
            return u'缺失值'
            
    return data


def SxbzxrCheck():
    data = getTable2('enterprise', 'sxbzxr')
    if data == u'缺失值':
        return u'缺失值'
    else:
        if len(data) == 0:
            IndexMaxLevel = 'L'
        else:
            IndexMaxLevel = 'H'

    if IndexMaxLevel == 'L':
        return 1
    else:
        return 0

result = SxbzxrCheck()